package com.micro.frog.common.base;


import lombok.Data;

import java.io.Serializable;

/**
 * 统一出参类
 *
 * @author :  ljh
 * @date : 2018/4/3
 **/
@Data
public class Result<T> implements Serializable {

    public static final String SUCCESS_CODE = "0000";
    public static final String ERROR_CODE = "-9999";
    public static final String DEFAULT_MSG = "OK";
    protected Boolean success = true;
    protected String code = SUCCESS_CODE;
    protected String msg;
    private T data;

    private Result() {
    }

    private Result(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> Result<T> success(String code, String msg, T data) {
        return new Result<>(code, msg, data);
    }

    public static <T> Result<T> success(String msg, T data) {
        return success(SUCCESS_CODE, msg, data);
    }

    public static <T> Result<T> success(T data) {
        return success(DEFAULT_MSG, data);
    }

    public static <T> Result<T> success() {
        return success(null);
    }

    public static <T> Result<T> error(String code, String msg) {
        return new Result<>(code, msg, null);
    }

    public static <T> Result<T> error(String msg) {
        return error(ERROR_CODE, msg);
    }
}
